Built-in module audioop

audioop The audioop module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples of 8, 16 or 32 bits wide, stored in Python strings. This is the same format as used by the al and sunaudiodev modules. All scalar items are integers, unless specified otherwise. A few of the more complicated operations only take 16-bit samples, otherwise the sample size (in bytes) is always a parameter of the operation. The module defines the following variables and functions:
\begin{excdesc}{error}
This exception is raised on all errors, such as unknown number of bytes
per sample, etc.
\end{excdesc}

\begin{funcdesc}{add}{fragment1\, fragment2\, width}
This function returns a fra...
...\code{2} or \code{4}. Both fragments should have the same length.
\end{funcdesc}

\begin{funcdesc}{adpcm2lin}{adpcmfragment\, width\, state}
This routine decodes ...
...state})}
where the sample has the width specified in \var{width}.
\end{funcdesc}

\begin{funcdesc}{adpcm32lin}{adpcmfragment\, width\, state}
This routine decodes an alternative 3-bit ADPCM code. See
\code{lin2adpcm3} for details.
\end{funcdesc}

\begin{funcdesc}{avg}{fragment\, width}
This function returns the average over all samples in the fragment.
\end{funcdesc}

\begin{funcdesc}{avgpp}{fragment\, width}
This function returns the average peak...
...ering is done, so the usefulness of this routine
is questionable.
\end{funcdesc}

\begin{funcdesc}{bias}{fragment\, width\, bias}
This function returns a fragment that is the original fragment with a
bias added to each sample.
\end{funcdesc}

\begin{funcdesc}{cross}{fragment\, width}
This function returns the number of zero crossings in the fragment
passed as an argument.
\end{funcdesc}

\begin{funcdesc}{findfactor}{fragment\, reference}
This routine (which only acce...
...e taken by this routine is proportional to \code{len(fragment)}. 
\end{funcdesc}

\begin{funcdesc}{findfit}{fragment\, reference}
This routine (which only accepts...
... \var{factor} the floating-point factor as per \code{findfactor}.
\end{funcdesc}

\begin{funcdesc}{findmax}{fragment\, length}
This routine (which only accepts 2-...
...al.

The routine takes time proportional to \code{len(fragment)}.
\end{funcdesc}

\begin{funcdesc}{getsample}{fragment\, width\, index}
This function returns the value of sample \var{index} from the
fragment.
\end{funcdesc}

\begin{funcdesc}{lin2lin}{fragment\, width\, newwidth}
This function converts samples between 1-, 2- and 4-byte formats.
\end{funcdesc}

\begin{funcdesc}{lin2adpcm}{fragment\, width\, state}
This function converts sam...
...frag} is
the ADPCM coded fragment packed 2 4-bit values per byte.
\end{funcdesc}

\begin{funcdesc}{lin2adpcm3}{fragment\, width\, state}
This is an alternative AD...
...e to laziness on the side of the author). Its use is
discouraged.
\end{funcdesc}

\begin{funcdesc}{lin2ulaw}{fragment\, width}
This function converts samples in t...
... bit
samples. It is used by the Sun audio hardware, among others.
\end{funcdesc}

\begin{funcdesc}{minmax}{fragment\, width}
This function returns a tuple consist...
... minimum and maximum
values of all samples in the sound fragment.
\end{funcdesc}

\begin{funcdesc}{max}{fragment\, width}
This function returns the maximum of the {\em absolute value} of all
samples in a fragment.
\end{funcdesc}

\begin{funcdesc}{maxpp}{fragment\, width}
This function returns the maximum peak-peak value in the sound fragment.
\end{funcdesc}

\begin{funcdesc}{mul}{fragment\, width\, factor}
Mul returns a fragment that has...
... floating-point value \var{factor}. Overflow is
silently ignored.
\end{funcdesc}

\begin{funcdesc}{reverse}{fragment\, width}
This function reverses the samples in a fragment and returns the
modified fragment.
\end{funcdesc}

\begin{funcdesc}{tomono}{fragment\, width\, lfactor\, rfactor} 
This function co...
...ar{rfactor} before adding the two channels to give a mono signal.
\end{funcdesc}

\begin{funcdesc}{tostereo}{fragment\, width\, lfactor\, rfactor}
This function g...
...lied by \var{lfactor}
and right channel samples by \var{rfactor}.
\end{funcdesc}

\begin{funcdesc}{mul}{fragment\, width\, factor}
Mul returns a fragment that has...
... floating-point value \var{factor}. Overflow is
silently ignored.
\end{funcdesc}
rmsfragment  width  factor Returns the root-mean-square of the fragment, i.e. the square root of the quotient of the sum of all squared sample value, divided by the sumber of samples.